<template>
  <view class="ikz-school">
    <ikz-loading :css-data="loading_css"></ikz-loading>
    <ikz-topbg></ikz-topbg>
    <!-- type == 1-->
    <block v-if="form_data.type == 1">
      <view class="ikz-form-input-box">
        <image
          class="ikz-form-input-img"
          src="/static/campus/takeaddr.png"
        ></image>
        <input
          v-model="form_data.start"
          class="ikz-form-input"
          placeholder="取货地点(必填)"
        />
      </view>
      <view class="ikz-form-input-box ikz-afters" @click="goaddress">
        <image
          class="ikz-form-input-img"
          src="/static/campus/giveaddr.png"
        ></image>
        <view v-if="!address_default">收货地点(必选)</view>
        <view class="ikz-form-address" v-else>
          {{ address_default.name }}-{{ address_default.mobile }}
          <view class="ikz-form-address-detail">
            {{ address_default.group_name }}-{{ address_default.detail }}
          </view>
        </view>
      </view>

      <view class="ikz-tab ikz-tab-content" style="margin-top: 70rpx">
        <view
          :class="['ikz-tab-item', activeTab === 'immediate' ? 'active' : '']"
          @click="switchTab('immediate')"
        >
          立即配送
        </view>
        <view
          :class="['ikz-tab-item', activeTab === 'reserve' ? 'active' : '']"
          @click="switchTab('reserve')"
        >
          预约单
        </view>
      </view>
      <view class="ikz-tab-content">
        <block v-if="activeTab === 'immediate'">
          <view class="ikz-form-input-box ikz-afters">
            <image
              class="ikz-form-input-img"
              src="/static/campus/time.png"
            ></image>
            <view style="width: 80%">
              <ikz-datetime @returnTime="returnTime"></ikz-datetime>
            </view>
          </view>
        </block>
        <block v-if="activeTab === 'reserve'">
          <view class="ikz-form-input-box ikz-afters">
            <image
              class="ikz-form-input-img"
              src="/static/campus/time.png"
            ></image>
            <view style="width: 80%">
              <ikz-datetime2 @returnTime="returnTime"></ikz-datetime2>
            </view>
          </view>
        </block>
      </view>

      <!-- 其他信息 -->
      <view class="ikz-tips">
        <view class="ikz-tips-title"> 帮助内容（必填） </view>
        <view class="ikz-tips-box">
          <textarea
            v-model="form_data.information"
            class="ikz-tips-text"
            placeholder="请输入要帮助的内容"
          ></textarea>
        </view>
      </view>
      <!-- <view class="ikz-take">
       <ikz-updata></ikz-updata>
      </view> -->
      <view class="ikz-form-price-box">
        <view class="ikz-form-price-title"> 跑腿费 </view>
        <input
          @input="check"
          @blur="checkPrice"
          v-model="form_data.price"
          type="digit"
          class="ikz-form-price-input"
          style="width: 75%"
          :placeholder="'请输入跑腿费最低' + min_price + '元'"
        />
      </view>
    </block>

    <!-- type == 1-->
    <!-- type == 2 -->
    <block v-if="form_data.type == 2">
      <view class="ikz-form-input-box ikz-afters" @click="getExpress()">
        <image
          class="ikz-form-input-img"
          src="/static/campus/takeaddr.png"
        ></image>
        <view class="ikz-form-input">
          {{ point_info.title || "取货地点(必选)" }}
        </view>
      </view>
      <view class="ikz-form-input-box ikz-afters" @click="goaddress">
        <image
          class="ikz-form-input-img"
          src="/static/campus/giveaddr.png"
        ></image>
        <view v-if="!address_default">收货地点(必选)</view>
        <view class="ikz-form-address" v-else>
          {{ address_default.name }}-{{ address_default.mobile }}
          <view class="ikz-form-address-detail">
            {{ address_default.group_name }}-{{ address_default.detail }}
          </view>
        </view>
      </view>
      <view class="ikz-form-input-box ikz-afters">
        <image class="ikz-form-input-img" src="/static/campus/time.png"></image>
        <view style="width: 80%">
          <ikz-datetime @returnTime="returnTime"></ikz-datetime>
        </view>
      </view>
      <view class="ikz-take" v-for="(item, index) in express_box" :key="index">
        <image class="ikz-take-img" src="/static/campus/box.png"></image>
        <view class="ikz-take-center">
          <view class="ikz-take-title">
            {{ item.type }}：￥{{ item.price }}
          </view>
          <view class="ikz-take-tips">
            {{ item.desc }}
          </view>
        </view>
        <view class="ikz-take-right">
          <view style="width: 50rpx; height: 50rpx">
            <image
              v-if="item.number"
              class="ikz-take-option"
              src="/static/campus/reduce.png"
              @click="reduceExpress(index)"
            ></image>
          </view>
          <view class="ikz-take-num">{{ item.number || "" }}</view>
          <image
            class="ikz-take-option"
            src="/static/campus/add.png"
            @click="addExpress(index)"
          ></image>
        </view>
      </view>
      <view class="ikz-tips">
        <view class="ikz-tips-title"> 取件信息（必填） </view>
        <view class="ikz-tips-box">
          <textarea
            class="ikz-tips-text"
            v-model="form_data.information"
            placeholder="请备注姓名电话及粘贴取件短信（此信息仅抢单员可见）"
          ></textarea>
        </view>
      </view>
    </block>

    <!-- type == 2 -->

    <!-- type == 3 -->
    <block v-if="form_data.type == 3">
      <view class="ikz-form-input-box ikz-afters">
        <image class="ikz-form-input-img" src="/static/campus/game.png"></image>
        <picker
          class="ikz-form-input"
          @change="gamePickerChange"
          :value="game_name_index"
          :range="game_name_data"
          range-key="name"
        >
          <view>{{ game_name_data[game_name_index].name }}</view>
        </picker>
      </view>
      <view class="ikz-form-input-box ikz-afters">
        <image class="ikz-form-input-img" src="/static/campus/time.png"></image>
        <picker
          class="ikz-form-input"
          @change="gameTimePickerChange"
          :value="game_time_index"
          :range="game_time_data"
          range-key="name"
        >
          <view>{{ game_time_data[game_time_index].name }}</view>
        </picker>
      </view>
      <!-- 其他信息 -->
      <view class="ikz-tips">
        <view class="ikz-tips-title"> 游戏信息 </view>
        <view class="ikz-tips-box">
          <textarea
            v-model="form_data.information"
            class="ikz-tips-text"
            placeholder="请输入游戏信息"
          ></textarea>
        </view>
      </view>
      <!-- <view class="ikz-take">
       <ikz-updata></ikz-updata> 
      </view> -->
      <view class="ikz-form-price-box">
        <view class="ikz-form-price-title"> 游戏ID </view>
        <input
          v-model="form_data.game_id"
          class="ikz-form-price-input"
          style="width: 75%"
          placeholder="填写游戏ID或游戏账号"
        />
      </view>
      <view class="ikz-form-price-box">
        <view class="ikz-form-price-title"> 抢单限制 </view>
        <picker
          class="ikz-form-price-input"
          style="width: 75%"
          @change="gameGenderPickerChange"
          :value="game_gender_index"
          :range="game_gender"
        >
          <view>{{ game_gender[game_gender_index] }}</view>
        </picker>
      </view>
      <view class="ikz-form-price-box">
        <view class="ikz-form-price-title"> 陪玩费 </view>
        <input
          @input="check"
          @blur="checkPrice"
          v-model="form_data.price"
          type="digit"
          class="ikz-form-price-input"
          style="width: 75%"
          :placeholder="'请输入陪玩费最低' + min_price + '元'"
        />
      </view>
    </block>
    <!-- type == 3 -->
    <!-- type == 4-->
    <block v-if="form_data.type == 4">
      <view class="ikz-form-input-box ikz-afters" @click="goaddress">
        <image
          class="ikz-form-input-img"
          src="/static/campus/giveaddr.png"
        ></image>
        <view v-if="!address_default">收货地点(必选)</view>
        <view class="ikz-form-address" v-else>
          {{ address_default.name }}-{{ address_default.mobile }}
          <view class="ikz-form-address-detail">
            {{ address_default.group_name }}-{{ address_default.detail }}
          </view>
        </view>
      </view>
      <view class="ikz-form-input-box ikz-afters">
        <image
          class="ikz-form-input-img"
          src="/static/campus/ztime.png"
        ></image>
        <picker
          class="ikz-form-input"
          @change="leasePickerChange"
          :value="lease_index"
          :range="lease_time"
        >
          <view>{{ lease_time[lease_index] }}</view>
        </picker>
      </view>
      <view class="ikz-form-input-box ikz-afters">
        <image
          class="ikz-form-input-img"
          src="/static/campus/gettime.png"
        ></image>
        <picker
          mode="time"
          @change="hopeArrivePickerChange"
          :value="form_data.hope_arrive"
          start="00:00"
          end="24:59"
          class="ikz-form-input"
        >
          <view>预计{{ form_data.hope_arrive }}交货</view>
        </picker>
      </view>
      <!-- 其他信息 -->
      <view class="ikz-tips">
        <view class="ikz-tips-title"> 租借物品需求（必填） </view>
        <view class="ikz-tips-box">
          <textarea
            v-model="form_data.information"
            class="ikz-tips-text"
            placeholder="请输入租借物品需求"
          ></textarea>
        </view>
      </view>
      <!-- <view class="ikz-take">
       <ikz-updata></ikz-updata>
      </view> -->
      <view class="ikz-form-price-box">
        <view class="ikz-form-price-title"> 租借费 </view>
        <input
          @input="check"
          @blur="checkPrice"
          v-model="form_data.price"
          type="digit"
          class="ikz-form-price-input"
          style="width: 75%"
          :placeholder="'请输入租借费最低' + min_price + '元'"
        />
      </view>
    </block>

    <!-- type == 5-->
    <block v-if="form_data.type == 5">
      <view class="ikz-form-input-box">
        <image class="ikz-form-input-img" src="/static/campus/down.png"></image>
        <input
          v-model="form_data.down_url"
          class="ikz-form-input"
          placeholder="下载链接(必填)"
        />
      </view>
      <view class="ikz-form-input-box">
        <image
          class="ikz-form-input-img"
          src="/static/campus/email.png"
        ></image>
        <input
          v-model="form_data.receive_email"
          class="ikz-form-input"
          placeholder="收货邮箱(必填)"
        />
      </view>
      <view class="ikz-form-price-box">
        <view class="ikz-form-price-title"> 下载费 </view>
        <input
          @input="check"
          @blur="checkPrice"
          v-model="form_data.price"
          type="digit"
          class="ikz-form-price-input"
          style="width: 75%"
          :placeholder="'请输入下载费最低' + min_price + '元'"
        />
      </view>
      <view class="ikz-tips">
        <view class="ikz-tips-title"> 下载说明 </view>
        <view class="ikz-tips-box" style="height: auto">
          <rich-text :nodes="file_info"></rich-text>
        </view>
      </view>
    </block>
    <!-- type == 5-->

    <!-- type == 6-->
    <block v-if="form_data.type == 6">
      <view class="ikz-form-input-box ikz-afters" @click="goaddress">
        <image
          class="ikz-form-input-img"
          src="/static/campus/giveaddr.png"
        ></image>
        <view v-if="!address_default.name">收货地点(必选)</view>
        <view v-else class="ikz-form-address">
          {{ address_default.name }}-{{ address_default.mobile }}
          <view class="ikz-form-address-detail">
            {{ address_default.group_name }}-{{ address_default.detail }}
          </view>
        </view>
      </view>
      <!-- 其他信息 -->
      <view class="ikz-tips">
        <view class="ikz-tips-title"> 帮助内容（必填） </view>
        <view class="ikz-tips-box">
          <textarea
            v-model="form_data.information"
            class="ikz-tips-text"
            placeholder="请输入要帮助的内容"
          ></textarea>
        </view>
      </view>
      <view class="ikz-form-price-box">
        <view class="ikz-form-price-title"> 帮助费 </view>
        <input
          @input="check"
          @blur="checkPrice"
          v-model="form_data.price"
          type="digit"
          class="ikz-form-price-input"
          style="width: 75%"
          :placeholder="'请输入帮助费最低' + min_price + '元'"
        />
      </view>
    </block>
    <!-- type == 6-->

    <view class="ikz-tips">
      <view class="ikz-tips-title"> 备注信息 </view>
      <view class="ikz-tips-box">
        <textarea
          v-model="form_data.remarks"
          class="ikz-tips-text"
          placeholder="请输入备注信息"
        ></textarea>
      </view>
    </view>
    <view class="ikz-take">
      <ikz-updata @returnFiles="returnFiles"></ikz-updata>
    </view>
    <view style="height: 230rpx"> </view>
    <view class="ikz-bottom">
      <view class="ikz-bottom-box">
        <view class="ikz-bottom-price">￥{{ form_data.total_fee || 0 }}</view>
        <view class="ikz-bottom-btn" @click="setUp"> 立即提交 </view>
      </view>
    </view>
  </view>
</template>

<script>
import ikzLoading from "@/pages/Component/Public/Loading/loading.vue";
import ikzTopbg from "@/pages/Component/Public/Topbg/public/topbg/topbg.vue";
import ikzUpdata from "@/pages/Component/Public/Updata/public/updata/updata.vue";
import ikzDatetime from "@/pages/Component/Public/Pickertime/public/datetime1/index.vue";
import ikzDatetime2 from "@/pages/Component/Public/Pickertime/public/datetime2/index.vue";
var app = getApp();
import ikz from "@/pages/Common/tools.js";
export default {
  components: {
    ikzLoading,
    ikzTopbg,
    ikzDatetime2,
    ikzUpdata,
    ikzDatetime,
  },
  data() {
    return {
      address_default: "",
      loading_css: {
        display: "flex",
      },
      activeTab: "immediate", // 默认选中立即配送
      form_data: {
        type: 1,
        game_platform_name: "", //平台名称
        game_platform: "", //游戏平台
        game_time: "1小时", //游戏时间
        game_id: "", //游戏ID
        receive_limit: "不限性别", //游戏抢单限制
        lease_duration: "1小时归还", //租借时长
        down_url: "", //下载链接
        receive_email: "", //收件邮箱
        start: "",
        destination: "",
        hope_arrive: "",
        information: "",
        price: "",
        remarks: "",
        reward: "",
        total_fee: 0,
        annex_information_images: [],
        express_temp: [],
      },
      point_info: "",
      express_box: [],
      files: [],
      game_name_data: [], //游戏陪玩
      game_name_index: 0,
      game_time_data: [
        {
          id: 1,
          name: "1小时",
        },
        {
          id: 2,
          name: "2小时",
        },
        {
          id: 3,
          name: "3小时",
        },
        {
          id: 4,
          name: "4小时",
        },
      ], //陪玩时间
      game_time_index: 0,
      game_gender: ["不限性别", "仅限男生", "仅限女生"],
      game_gender_index: 0,
      lease_time: ["1小时归还", "2小时归还", "3小时归还", "4小时归还"], //租借时长
      lease_index: 0,
      lease_return_time: "09:00", //租借时长
      up_status: 2,
      file_info: "",
      min_price: 2,
    };
  },
  onLoad(options) {
    if (!options) {
      return;
    }
    this.form_data.type = options.type;
    if (this.form_data.type == 1) {
      this.loading_css.display = "none";
      uni.setNavigationBarTitle({
        title: "校园跑腿",
      });
    } else if (this.form_data.type == 2) {
      this.expressBox((res) => {
        this.loading_css.display = "none";
      });
      uni.setNavigationBarTitle({
        title: "快递代取",
      });
    } else if (this.form_data.type == 3) {
      this.ganmeList((res) => {
        this.loading_css.display = "none";
      });
      uni.setNavigationBarTitle({
        title: "游戏陪玩",
      });
    } else if (this.form_data.type == 4) {
      this.form_data.hope_arrive = "09:00";
      this.loading_css.display = "none";
      uni.setNavigationBarTitle({
        title: "租借服务",
      });
    } else if (this.form_data.type == 5) {
      this.loading_css.display = "none";
      uni.setNavigationBarTitle({
        title: "文档下载",
      });
      this.fileInfo();
    } else if (this.form_data.type == 6) {
      this.loading_css.display = "none";
      uni.setNavigationBarTitle({
        title: "其他帮助",
      });
    }
  },
  onShow() {
    this.address_default = app.globalData.user_address.address_default;
    this.form_data.destination = this.address_default.id;
    if (this.form_data.type == 2) {
      this.point_info = app.globalData.point_info || "";
      this.form_data.start = app.globalData.point_info.id || "";
    }
    this.$forceUpdate();
  },
  methods: {
    fileInfo() {
      var path = "/xyb/same/document_download_instructions";
      var data = {};
      ikz.post(path, data, (res) => {
        if (res.data.code) {
          this.file_info = res.data.data.value;
        } else {
          uni.showModal({
            title: "提示",
            content: res.data.msg,
            showCancel: false,
            success: function (res) {},
          });
        }
      });
    },
    setUsp() {},
    /* type == 4*/
    leasePickerChange(e) {
      this.lease_index = e.detail.value;
      this.form_data.lease_duration = this.lease_time[this.lease_index];
    },
    hopeArrivePickerChange(e) {
      this.form_data.hope_arrive = e.detail.value;
    },
    /* type == 4*/
    /* type == 3*/
    gameGenderPickerChange(e) {
      this.game_gender_index = e.detail.value;
      this.receive_limit = this.game_gender[this.game_gender_index];
    },
    gamePickerChange(e) {
      this.game_name_index = e.detail.value;
      this.form_data.game_platform =
        this.game_name_data[this.game_name_index].id;
      this.form_data.game_platform_name =
        this.game_name_data[this.game_name_index].name;
    },
    gameTimePickerChange(e) {
      console.log(222);
      this.game_time_index = e.detail.value;
      this.form_data.game_time = this.game_time_data[this.game_time_index].name;
    },
    ganmeList(fn) {
      var path = "/xyb/agent_games/index";
      var data = {};
      ikz.post(path, data, (res) => {
        if (res.data.code) {
          this.game_name_data = res.data.data;
          this.form_data.game_platform = this.game_name_data[0].id;
          this.form_data.game_platform_name = this.game_name_data[0].name;
        } else {
          uni.showModal({
            title: "提示",
            content: res.data.msg,
            showCancel: false,
            success: function (res) {},
          });
        }
        fn();
      });
    },
    /* type==2*/
    //快递点地址
    getExpress() {
      uni.navigateTo({
        url: "/pages/Component/Module/Campus/Program/Express/point/index",
      });
    },
    //增加包裹
    addExpress(index) {
      this.express_box[index].number++;
      this.form_data.total_fee = (
        parseFloat(this.express_box[index].price) +
        parseFloat(this.form_data.total_fee)
      ).toFixed(2);
    },
    //减少包裹
    reduceExpress(index) {
      this.express_box[index].number--;
      this.form_data.total_fee = (
        parseFloat(this.form_data.total_fee) -
        parseFloat(this.express_box[index].price)
      ).toFixed(2);
    },
    //请求包裹数据
    expressBox(fn) {
      var path = "/xyb/same/express_config";
      var data = {};
      ikz.post(path, data, (res) => {
        if (res.data.code) {
          this.express_box = res.data.data.express_config;
          for (var i = 0; i < this.express_box.length; i++) {
            this.express_box[i].number = 0;
            this.express_box[i].price = res.data.data.express_config[i].price;
          }
        } else {
          uni.showModal({
            title: "提示",
            content: res.data.msg,
            showCancel: false,
            success: function (res) {},
          });
        }
        fn();
      });
    },
    /* type == 2*/
    //返回图片数据
    returnFiles(e) {
      this.files = e;
      console.log(e);
    },
    //提交数据
    setUp() {
      if (!uni.getStorageSync("local_user_session")) {
        uni.navigateTo({
          url: "/pages/login/index",
        });
        return;
      }
      this.up_status = 3;
      if (this.form_data.type == 1) {
        if (!this.address_default) {
          wx.showToast({
            title: "请填选择收货地址",
            icon: "none",
            duration: 2000,
          });
          return;
        }
        this.runerrandsUp();
      } else if (this.form_data.type == 2) {
        if (!this.address_default) {
          wx.showToast({
            title: "请填选择收货地址",
            icon: "none",
            duration: 2000,
          });
          return;
        }
        this.expressUp();
      } else if (this.form_data.type == 3) {
        this.gameUp();
      } else if (this.form_data.type == 4) {
        if (!this.address_default) {
          wx.showToast({
            title: "请填选择收货地址",
            icon: "none",
            duration: 2000,
          });
          return;
        }
        this.leaseUp();
      } else if (this.form_data.type == 5) {
        this.fileUp();
      } else if (this.form_data.type == 6) {
        if (!this.address_default) {
          wx.showToast({
            title: "请填选择收货地址",
            icon: "none",
            duration: 2000,
          });
          return;
        }
        this.otherUp();
      }
    },
    otherUp() {
      uni.showLoading({
        title: "加载中",
      });
      if (this.form_data.price == "") {
        wx.showToast({
          title: "请填写帮助费",
          icon: "none",
          duration: 2000,
        });
        return;
      }
      if (
        !Number.isInteger(parseFloat(this.form_data.price)) || // 检查是否为整数
        parseFloat(this.form_data.price) < parseFloat(this.min_price)
      ) {
        wx.showToast({
          title: `费用必须为整数且不低于${this.min_price}元`,
          icon: "error",
          duration: 2000,
        });
        return;
      }
      if (this.form_data.price >= 10000) {
        wx.showToast({
          title: "帮助费小于1万元",
          icon: "error",
          duration: 2000,
        });
        return;
      }
      if (this.form_data.destination == "") {
        wx.showToast({
          title: "请选择收货地点",
          icon: "error",
          duration: 2000,
        });
        return;
      }
      if (this.form_data.information == "") {
        wx.showToast({
          title: "请输入帮助内容",
          icon: "error",
          duration: 2000,
        });
        return;
      }
      this.goOrderIndex();
    },
    fileUp() {
      uni.showLoading({
        title: "加载中",
      });
      if (this.form_data.price == "") {
        wx.showToast({
          title: "请填写下载费",
          icon: "none",
          duration: 2000,
        });
        return;
      }
      if (parseFloat(this.form_data.price) < parseFloat(this.min_price)) {
        wx.showToast({
          title: "下载费最低为" + this.min_price + "元",
          icon: "error",
          duration: 2000,
        });
        return;
      }
      if (this.form_data.down_url == "") {
        wx.showToast({
          title: "请输入下载链接",
          icon: "error",
          duration: 2000,
        });
        return;
      }
      if (this.form_data.receive_email == "") {
        wx.showToast({
          title: "请输入收件邮箱",
          icon: "error",
          duration: 2000,
        });
        return;
      }
      this.goOrderIndex();
    },
    leaseUp() {
      uni.showLoading({
        title: "加载中",
      });
      if (this.form_data.price == "") {
        wx.showToast({
          title: "请填写租借费",
          icon: "none",
          duration: 2000,
        });
        return;
      }
      if (parseFloat(this.form_data.price) < parseFloat(this.min_price)) {
        wx.showToast({
          title: "租借费最低为" + this.min_price + "元",
          icon: "error",
          duration: 2000,
        });
        return;
      }
      if (this.form_data.price >= 10000) {
        wx.showToast({
          title: "租借费小于1万元",
          icon: "error",
          duration: 2000,
        });
        return;
      }
      if (this.form_data.destination == "") {
        wx.showToast({
          title: "请选择收货地点",
          icon: "error",
          duration: 2000,
        });
        return;
      }
      if (this.form_data.information == "") {
        wx.showToast({
          title: "请输入租借物品需求",
          icon: "error",
          duration: 2000,
        });
        return;
      }
      this.goOrderIndex();
    },
    //游戏陪玩
    gameUp() {
      uni.showLoading({
        title: "加载中",
      });
      if (this.form_data.game_id == "") {
        wx.showToast({
          title: "请填写游戏ID或游戏账号",
          icon: "none",
          duration: 2000,
        });
        return;
      }
      if (this.form_data.price == "") {
        wx.showToast({
          title: "请填写陪玩费",
          icon: "none",
          duration: 2000,
        });
        return;
      }
      if (parseFloat(this.form_data.price) < parseFloat(this.min_price)) {
        wx.showToast({
          title: "陪玩费最低为" + this.min_price + "元",
          icon: "error",
          duration: 2000,
        });
        return;
      }
      if (this.form_data.price >= 10000) {
        wx.showToast({
          title: "陪玩费小于1万元",
          icon: "error",
          duration: 2000,
        });
        return;
      }
      if (this.form_data.information == "") {
        wx.showToast({
          title: "请输入游戏信息",
          icon: "error",
          duration: 2000,
        });
        return;
      }
      this.goOrderIndex();
    },
    //快递
    expressUp() {
      uni.showLoading({
        title: "加载中",
      });
      //判断填写数据是否正确
      if (this.form_data.start == "") {
        wx.showToast({
          title: "请输入取货地点",
          icon: "error",
          duration: 2000,
        });
        return;
      }
      if (this.form_data.destination == "") {
        wx.showToast({
          title: "请选择收货地点",
          icon: "error",
          duration: 2000,
        });
        return;
      }
      if (this.form_data.hope_arrive == "") {
        wx.showToast({
          title: "请选择预计送达时间",
          icon: "error",
          duration: 2000,
        });
        return;
      }
      if (this.form_data.information == "") {
        wx.showToast({
          title: "请输入取件信息",
          icon: "error",
          duration: 2000,
        });
        return;
      }
      this.form_data.express_temp = [];
      for (var i = 0; i < this.express_box.length; i++) {
        if (this.express_box[i].number) {
          this.form_data.express_temp.push(this.express_box[i]);
        }
      }
      if (this.form_data.express_temp.length == 0) {
        wx.showToast({
          title: "请选择快递单件",
          icon: "error",
          duration: 2000,
        });
        return;
      }
      this.form_data.express_temp = JSON.stringify(this.form_data.express_temp);
      console.log(this.form_data);
      this.goOrderIndex();
    },
    runerrandsUp() {
      uni.showLoading({
        title: "加载中",
      });
      //判断填写数据是否正确
      if (this.form_data.start == "") {
        wx.showToast({
          title: "请输入取货地点",
          icon: "error",
          duration: 2000,
        });
        return;
      }
      if (this.form_data.destination == "") {
        wx.showToast({
          title: "请选择收货地点",
          icon: "error",
          duration: 2000,
        });
        return;
      }
      if (this.form_data.hope_arrive == "") {
        wx.showToast({
          title: "请选择预计送达时间",
          icon: "error",
          duration: 2000,
        });
        return;
      }
      if (this.form_data.information == "") {
        wx.showToast({
          title: "请输入帮助信息",
          icon: "error",
          duration: 2000,
        });
        return;
      }
      if (this.form_data.price == "") {
        wx.showToast({
          title: "请输入跑腿费",
          icon: "error",
          duration: 2000,
        });
        return;
      }
     if (!Number.isInteger(parseFloat(this.form_data.price))) { // 检查是否为整数
  wx.showToast({
    title: "跑腿费必须为整数",
    icon: "error",
    duration: 2000,
  });
  return;
}
if (parseFloat(this.form_data.price) < parseFloat(this.min_price)) { // 检查是否低于最低价格
  wx.showToast({
    title: "跑腿费最低为" + this.min_price + "元",
    icon: "error",
    duration: 2000,
  });
  return;
}
      if (this.form_data.price >= 10000) {
        wx.showToast({
          title: "跑腿费小于1万元",
          icon: "error",
          duration: 2000,
        });
        return;
      }
      this.goOrderIndex();
    },
    goOrderIndex() {
      if (this.files.length) {
        //循环上传图片
        this.upImg(0, (res) => {
          uni.hideLoading();
          this.form_data.total_price = this.form_data.total_fee;
          var path =
            "/pages/Component/Module/Campus/Program/Runerrands/detail/index";
          ikz.nav(path, "ln", this.form_data);
        });
      } else {
        uni.hideLoading();
        this.form_data.total_price = this.form_data.total_fee;
        var path =
          "/pages/Component/Module/Campus/Program/Runerrands/detail/index";
        ikz.nav(path, "ln", this.form_data);
      }
    },
    //上传图片
    upImg(index, fn) {
      uni.showLoading({
        title: "加载中",
      });
      var that = this;
      var path = "/common/upload";
      var data = {};
      ikz.up(path, data, "file", this.files[index], (res) => {
        var temp_result_data = JSON.parse(res.data);
        if (temp_result_data.code) {
          uni.hideLoading();
          that.form_data.annex_information_images.push(
            temp_result_data.data.url
          );
          if (that.files.length == index + 1) {
            fn();
          } else {
            index++;
            that.upImg(index, fn);
          }
        } else {
          uni.showModal({
            title: "提示",
            content: temp_result_data.msg,
            showCancel: false,
            success: function (res) {},
          });
          uni.hideLoading();
        }
      });
    },
    //返回时间
    returnTime(e) {
      this.form_data.hope_arrive = e;
    },
    switchTab(tab) {
      this.activeTab = tab;
      this.form_data.hope_arrive = this.returnTime;
    },
    check: function (e) {
      //正则表达试
      e.target.value = e.target.value.match(/^\d*(\.?\d{0,2})/g)[0] || "";
      //重新赋值给input
      this.$nextTick(() => {
        this.form_data.price = e.target.value;
      });
    },
    checkPrice() {
      if (this.form_data.price) {
        this.form_data.price = parseFloat(this.form_data.price).toFixed(2);
      }
      this.form_data.total_fee = this.form_data.price;
    },
    //我的地址
    goaddress() {
      uni.navigateTo({
        url: "/pages/Component/Module/Address/Program/myAddress/index",
      });
    },
  },
};
</script>

<style lang="scss">
page {
  background: #f8f8f8;
  color: #333;
}

/* 顶部背景和标题样式 */
.ikz-top-bg {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 300rpx;
  background: linear-gradient(135deg, #FF5F15, #FF8F1F);
  z-index: -1;
}

/* 表单输入区域 */
.ikz-form-input-box {
  margin: 20rpx auto;
  padding: 25rpx 30rpx;
  width: 90%;
  background: #fff;
  border-radius: 16rpx;
  box-shadow: 0 4rpx 12rpx rgba(0,0,0,0.05);
  display: flex;
  align-items: center;
  
  .ikz-form-input-img {
    width: 40rpx;
    height: 40rpx;
    margin-right: 20rpx;
  }
  
  .ikz-form-input {
    flex: 1;
    font-size: 28rpx;
    color: #333;
  }
}

/* 选项卡样式 */
.ikz-tab {
  display: flex;
  margin: 30rpx auto;
  width: 90%;
  background: #fff;
  border-radius: 16rpx;
  box-shadow: 0 4rpx 12rpx rgba(0,0,0,0.05);
  
  .ikz-tab-item {
    flex: 1;
    text-align: center;
    padding: 20rpx 0;
    font-size: 28rpx;
    color: #666;
    
    &.active {
      color: #FF5F15;
      position: relative;
      
      &::after {
        content: '';
        position: absolute;
        bottom: 0;
        left: 50%;
        transform: translateX(-50%);
        width: 60%;
        height: 4rpx;
        background: #FF5F15;
        border-radius: 2rpx;
      }
    }
  }
}

/* 提示和文本区域 */
.ikz-tips {
  margin: 30rpx auto;
  width: 90%;
  background: #fff;
  border-radius: 16rpx;
  padding: 25rpx;
  box-shadow: 0 4rpx 12rpx rgba(0,0,0,0.05);
  
  .ikz-tips-title {
    font-size: 28rpx;
    font-weight: bold;
    margin-bottom: 20rpx;
  }
  
  .ikz-tips-text {
    width: 100%;
    height: 200rpx;
    padding: 20rpx;
    border: 1rpx solid #eee;
    border-radius: 12rpx;
    font-size: 26rpx;
    background: #f9f9f9;
  }
}

/* 底部操作栏 */
.ikz-bottom {
  position: fixed;
  bottom: 0;
  left: 0;
  width: 100%;
  height: 120rpx;
  background: #fff;
  box-shadow: 0 -4rpx 12rpx rgba(0,0,0,0.05);
  display: flex;
  align-items: center;
  justify-content: center;
  
  .ikz-bottom-box {
    width: 90%;
    height: 90rpx;
    background: linear-gradient(90deg, #FF5F15, #FF8F1F);
    border-radius: 45rpx;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 30rpx;
    
    .ikz-bottom-price {
      font-size: 32rpx;
      color: #fff;
      font-weight: bold;
    }
    
    .ikz-bottom-btn {
      font-size: 30rpx;
      color: #fff;
      font-weight: bold;
    }
  }
}

/* 快递包裹样式 */
.ikz-take {
  margin: 30rpx auto;
  width: 90%;
  background: #fff;
  border-radius: 16rpx;
  padding: 25rpx;
  box-shadow: 0 4rpx 12rpx rgba(0,0,0,0.05);
  
  .ikz-take-img {
    width: 80rpx;
    height: 80rpx;
  }
  
  .ikz-take-center {
    flex: 1;
    margin: 0 20rpx;
    
    .ikz-take-title {
      font-size: 28rpx;
      font-weight: bold;
    }
    
    .ikz-take-tips {
      font-size: 24rpx;
      color: #999;
    }
  }
  
  .ikz-take-right {
    display: flex;
    align-items: center;
    
    .ikz-take-option {
      width: 50rpx;
      height: 50rpx;
    }
    
    .ikz-take-num {
      margin: 0 20rpx;
      font-size: 28rpx;
    }
  }
}

/* 价格输入框 */
.ikz-form-price-box {
  margin: 30rpx auto;
  width: 90%;
  background: #fff;
  border-radius: 16rpx;
  padding: 25rpx;
  box-shadow: 0 4rpx 12rpx rgba(0,0,0,0.05);
  display: flex;
  align-items: center;
  
  .ikz-form-price-title {
    font-size: 28rpx;
    font-weight: bold;
    width: 25%;
  }
  
  .ikz-form-price-input {
    flex: 1;
    font-size: 28rpx;
    color: #333;
  }
}

/* 箭头指示器 */
.ikz-afters:after {
  content: " ";
  display: inline-block;
  height: 12rpx;
  width: 12rpx;
  border-width: 2rpx 2rpx 0 0;
  border-color: #999;
  border-style: solid;
  transform: rotate(45deg);
  position: absolute;
  right: 30rpx;
  top: 50%;
  margin-top: -6rpx;
}
</style>
